//
// Created by 紫霄 on 2020/4/24.
//

#ifndef LEETCODE_55_H
#define LEETCODE_55_H

struct TreeNode {
  int val;
  TreeNode *left;
  TreeNode *right;
  TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};
class Solution {
public:
  int maxDepth(TreeNode *root) {
    if (root)
      return 1 + getHeight(root);
    return 0;
  }
  int getHeight(TreeNode *root) {
    int leftHeight = -1;
    int rightHeight = -1;
    if (root->left) {
      leftHeight = getHeight(root->left);
    }
    if (root->right) {
      rightHeight = getHeight(root->right);
    }
    return (leftHeight > rightHeight ? leftHeight : rightHeight);
  }
};
#endif // LEETCODE_55_H
